﻿@using CommonSite.Common
@{
    Layout = "~/Views/Shared/_LayoutFrame.cshtml";
}

@section style
{
    <link type="text/css" rel="stylesheet" href="/Content/css-1.css" />
}

@if(ViewBag.Back)
{
<div>
    <a style="margin-left:2%;font-size:medium;" href="@ViewBag.BackUrl" target="_self">返回</a>
    <hr />
</div>
}

<div style="margin-left:2%;color:red;">
    <h3>@ViewBag.Flow["description"]</h3>
</div>


<div id="print">
<div id="info" class="tt-content">
    <div class="tt-title">
        <h3>@ViewBag.Flow["flowname"]</h3>
    </div>
    <div class="tt-body">
        @{
            Html.RenderPartial("~/Views/Shared/ViewTemplate.cshtml");
        }
    </div>
</div>
</div>

<div id="progress" class="tt-content">
    <div class="tt-body">
        <div id="grid">
        </div>
    </div>
    <div class="tt-foot">
        <div>
            @Html.Raw(ViewBag.Flow["flowdescription"])
        </div>
        <div style="text-align:center;margin-top:5px;">
        信诚天下、开拓未来&nbsp;&nbsp;&nbsp;&nbsp;制作部门:行政及人力资源部门
        </div>
    </div>
</div>

<div style="float:right;margin-top:5px;margin-right:20px;">
@if (ViewBag.CanCancel)
{
<form action="/Item/Cancel" method="post">
    <input type="hidden" name="flowid" value="@ViewBag.FlowId" />
    <input style="width:80px;height:30px;" type="button" value="撤销" onclick="oncancel()" />
    <input style="width:80px;height:30px;" type="button" value="预览并打印" onclick="preview()">
</form>
}
else
{
    <input style="width:80px;height:30px;" type="button" value="预览并打印" onclick="preview()">
}
</div>

<script type="text/javascript">
    function getStateText(item) {
        switch (item.state) {
            //0 关闭 1 初始 2 通过 3 拒绝 4 指派 5 跳过

            case 0:
                return '关闭';
            case 1:
                return '进行中';
            case 2:
                return '通过';
            case 3:
                return '拒绝';
            case 4:
                return '指派';
            case 5:
                return '跳过';
        }
    }

    function preview() {
        var w = window.open('', ''/*, 'location=no,titlebar=no,status=no'*/);
        //var head = w.document.getElementsByTagName('HEAD').item(0);
        //var style = w.document.createElement('link');
        //style.href = '/Content/css-1.css';
        //style.rel = 'stylesheet';
        //style.type = 'text/css';
        //head.appendChild(style);

        var progress =
            '<style type="text/css">html,body{background:#fff}.tt-content{position:relative}.tt-title{margin-top:5px;text-align:center}.tt-body{margin-top:5px;padding-left:2%;padding-right:2%}.tt-foot{height:30px;margin-top:5px;padding-left:2%;padding-right:2%}.tt-table{width:100%}.tt-table td{padding-left:20px;padding-right:20px}.c1,.c3,.c4,.c5,.c6,.c8,.c9,.c11{height:40px}.c2{height:80px}.c7{display:none}textarea{height:70px;width:99%}.c1 input{width:200px}.c5 input{width:60px}table{border-collapse:collapse}</style>' +
            '<div class="tt-content">' +
            '<div class="tt-title"><h3>审批进度</h3></div>' +
            '<div class="tt-body"><table class="tt-table" style="text-align:center;" border="1" cellspacing="0" bordercolor="#000"><thead><tr>' +
                '<th style="width:15%">&nbsp;</th>' +
                '<th style="width:10%">审批人</th>' +
                '<th style="width:10%">审批状态</th>' +
                '<th style="width:15%">审批时间</th>' +
                '<th style="width:50%">审批意见</th>' +
            '</tr></thead>';

        var data = liger.get('grid').getData();
        $.each(data, function (i, n) {
            if (n.State != 5) {
                progress +=
                    '<tr>' +
                        '<td>' + n.Name + '</td>' +
                        '<td>' + n.UserName + '</td>' +
                        '<td>' + getStateText(n) + '</td>' +
                        '<td>' + n.UpdatedTime + '</td>' +
                        '<td>' + (n.Result == '' ? '&nbsp;' : n.Result) + '</td>' +
                    '</tr>';
            }
        });

        progress += '</table></div></div>';
        w.document.body.innerHTML = $('#print').html() + progress;

        w.print();
    }
    
    function oncancel() {
        $.ligerDialog.confirm('是否撤销此申请?', '提示', function (r) {
            if (r) {
                $('form').submit();
            }
        });
    }

    $(document).ready(function () {
        $('#grid').ligerGrid({
            title: '审批进度',
            rownumbers: true,
            usePager: false,
            resizable: false,
            frozen: false,
            columns: [
                { name: 'taskname', display: '', width: 120 }
                , { name: 'username', display: '审批人', width: 120 }
                , {
                    name: 'state', display: '审批状态', width: 100,
                    render: getStateText
                }
                , { name: 'updatedtime', display: '审批时间', width: 120 }
                , { name: 'result', display: '审批意见', width: 300 }
            ],
            url: '/Item/WorkUsers?id=@ViewBag.FlowId'
        });
    });
</script>